﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BussinessLogicLayer.BussinessObject;
using DataAccessLayer;

namespace BussinessLogicLayer.ChucNangGV.CaiDat
{
    class CnGiaoVienCaiDat : ICNGiaoVien
    {
        #region Implementation of ICNGiaoVien

        public GiaoVien_GV LayThongTinGiaoVien(string magv)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            return tinChiEntities.GIAOVIENs.Where(giaovien => giaovien.MaGV == magv).Select(
                giaovien => new GiaoVien_GV()
                    {
                        ChuyenNganh = giaovien.Chuyennganh,
                        GioiTinh = giaovien.Gioitinh.Value,
                        MaGv = giaovien.MaGV,
                        MaKhoa = giaovien.MaKhoa,
                        NgaySinh = giaovien.Ngaysinh.Value,
                        QueQuan = giaovien.Quequan,
                        TenGv = giaovien.Hoten,
                        TenKhoa = giaovien.KHOA.Tenkhoa
                    }).First();
        }

        #endregion

        #region Implementation of ILayDoiTuongGv

        public List<string> LayDsKhoaGv(GiaoVien_GV gv)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            return tinChiEntities.LOPHPs.Where(lophp => lophp.MaGV == gv.MaGv).Select(lophp => lophp.Khoahoc).ToList();
        }

        public List<LopHpCnGvBo> LayDsLopHpGv(GiaoVien_GV gv, string khoa)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            return tinChiEntities.LOPHPs.Where(lophp => lophp.MaGV == gv.MaGv && lophp.Khoahoc == khoa)
                .Select(lophp => new LopHpCnGvBo
                    {
                        MaLopHp = lophp.MaLopHP,
                        KhoaHoc = khoa,
                        MaHp = lophp.MaHP,
                        TehHp = lophp.HocPhan.TenHP,
                        SoTinChi = lophp.HocPhan.Sotinchi.Value,
                        HeSoChuyenCan = lophp.MAUDIEM.Hesochuyencan.Value,
                        HeSoGiuaKy = lophp.MAUDIEM.Hesogiuaky.Value,
                        HeSoCuoiKy = lophp.MAUDIEM.Hesocuoiky.Value
                    }).ToList();
        }

        public List<DiemSvCnGvBo> LayDsDiemSvGv(GiaoVien_GV gv, LopHpCnGvBo lophp)
        {
            TinChiEntitiesDataContext tinChiEntities = Service.TinChiDataContext;
            return tinChiEntities.DIEMSVs.Where(diemsv => diemsv.MaLopHP == lophp.MaLopHp)
                .Select(diemsv => new DiemSvCnGvBo()
                                      {
                                          MaDiem = diemsv.MaDiem,
                                          MaSv = diemsv.MaSV,
                                          TenSv = diemsv.SINHVIEN.Hoten,
                                          DiemCc = diemsv.Diemchuyencan.Value,
                                          DiemGiuaKy = diemsv.Diemgiuaky.Value,
                                          DiemCuoiKy = diemsv.Diemcuoiky.Value,
                                          DiemTongKet = diemsv.Diemtongket.Value
                                      }).ToList();
        }

        #endregion
    }
}
